<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Blocks (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Blocks (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Blocks (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Statements.html" rel="up" title="Statements">
<link href="Statement-Sequences.html" rel="next" title="Statement Sequences">
<link href="Basic-Statements.html" rel="prev" title="Basic Statements">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en">
<div class="subsection-level-extent" id="Blocks">
<div class="nav-panel">
<p>
Next: <a href="Statement-Sequences.html" accesskey="n" rel="next">Statement Sequences</a>, Previous: <a href="Basic-Statements.html" accesskey="p" rel="prev">Basic Statements</a>, Up: <a href="Statements.html" accesskey="u" rel="up">Statements</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Blocks-1"><span>11.7.2 Blocks<a class="copiable-link" href="#Blocks-1"> &para;</a></span></h4>
<a class="index-entry-id" id="index-Blocks"></a>

<p>Block scopes and the variables they declare in GENERIC are
expressed using the <code class="code">BIND_EXPR</code> code, which in previous
versions of GCC was primarily used for the C statement-expression
extension.
</p>
<p>Variables in a block are collected into <code class="code">BIND_EXPR_VARS</code> in
declaration order through their <code class="code">TREE_CHAIN</code> field.  Any runtime
initialization is moved out of <code class="code">DECL_INITIAL</code> and into a
statement in the controlled block.  When gimplifying from C or C++,
this initialization replaces the <code class="code">DECL_STMT</code>.  These variables
will never require cleanups.  The scope of these variables is just the
body
</p>
<p>Variable-length arrays (VLAs) complicate this process, as their size
often refers to variables initialized earlier in the block and their
initialization involves an explicit stack allocation.  To handle this,
we add an indirection and replace them with a pointer to stack space
allocated by means of <code class="code">alloca</code>.  In most cases, we also arrange
for this space to be reclaimed when the enclosing <code class="code">BIND_EXPR</code> is
exited, the exception to this being when there is an explicit call to
<code class="code">alloca</code> in the source code, in which case the stack is left
depressed on exit of the <code class="code">BIND_EXPR</code>.
</p>
<p>A C++ program will usually contain more <code class="code">BIND_EXPR</code>s than
there are syntactic blocks in the source code, since several C++
constructs have implicit scopes associated with them.  On the
other hand, although the C++ front end uses pseudo-scopes to
handle cleanups for objects with destructors, these don&rsquo;t
translate into the GIMPLE form; multiple declarations at the same
level use the same <code class="code">BIND_EXPR</code>.
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Statement-Sequences.html">Statement Sequences</a>, Previous: <a href="Basic-Statements.html">Basic Statements</a>, Up: <a href="Statements.html">Statements</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
